import type { PageParam, PageResult } from '@vben/request';
import type { Dayjs } from 'dayjs';

import { requestClient } from '#/api/request';
export namespace PerBusinessFamilyStudyApi {
  /** 求学情况业务表信息 */
  export interface BusinessFamilyStudy {
    id: number; // 主键ID
    busiId?: string; // 业务主表ID
    familyStudyId: number; // 正式表ID，对应 per_family_study.id，用于修改或删除时关联
    employeeId?: number; // 人员ID，对应 per_employee.id
    relation: string; // 与本人关系（称谓）
    systemPersonId: number; // 系统人员ID，对应system_person.id
    familyName: string; // 姓名
    cardType: string; // 证件类型
    familyIdcard: string; // 证件号码
    studyCountry: string; // 求学国家
    schoolName: string; // 学校名称
    studyAbroadDate: string; // 出国时间
    annualExpense: string; // 每年留学费用
    expenseSource: string; // 费用来源
    isUsing: number; // 是否在读（1：是，0：否）
    status: number; // 是否有效（1：有效，0：无效）
    remarks: string; // 备注
    changeType: string; // 变更类型（add：新增，update：修改，delete：删除）
    changeContent: string; // 变更内容(JSON格式，仅修改时记录差异)
    auditStatus: number; // 审核状态（0 草稿 1 审核中 2 审核完成）
    finalAuditStatus: number; // 最终审核状态（0 待审核 1 审核通过 2 审核不通过）
    auditTime: string | Dayjs; // 审核完成时间
    auditor: string; // 审核人
    auditComment: string; // 审核意见
    metadata: string; // 其他参数
  }
}

/** 查询求学情况业务表分页 */
export function getBusinessFamilyStudyPage(
  data: PageParam,
  desensitize: boolean,
  encrypt: boolean,
) {
  return requestClient.post<
    PageResult<PerBusinessFamilyStudyApi.BusinessFamilyStudy>
  >('/per/business-family-study/page', data, { desensitize, encrypt });
}

/** 查询求学情况业务表详情 */
export function getBusinessFamilyStudy(params: { id: number }) {
  return requestClient.get<PerBusinessFamilyStudyApi.BusinessFamilyStudy>(
    `/per/business-family-study/get?id=${params.id}`,
  );
}

/** 新增求学情况业务表 */
export function createBusinessFamilyStudy(
  data: PerBusinessFamilyStudyApi.BusinessFamilyStudy,
) {
  return requestClient.post('/per/business-family-study/create', data);
}

/** 修改求学情况业务表 */
export function updateBusinessFamilyStudy(
  data: PerBusinessFamilyStudyApi.BusinessFamilyStudy,
) {
  return requestClient.put('/per/business-family-study/update', data);
}

/** 删除求学情况业务表 */
export function deleteBusinessFamilyStudy(params: { id: number }) {
  return requestClient.delete(
    `/per/business-family-study/delete?id=${params.id}`,
  );
}

/** 批量删除求学情况业务表 */
export function deleteBusinessFamilyStudyList(ids: number[]) {
  return requestClient.delete(
    `/per/business-family-study/delete-list?ids=${ids.join(',')}`,
  );
}

/** 导出求学情况业务表 */
export function exportBusinessFamilyStudy(params: any) {
  return requestClient.download('/per/business-family-study/export-excel', {
    params,
  });
}

/** 根据业务主表id去查询业务数据 */
export function getFamilyStudyBusiId(data: any) {
  return requestClient.post<PerBusinessFamilyStudyApi.BusinessFamilyStudy>(
    '/per/business-family-study/getFamilyStudyBusiId',
    data,
  );
}

/** 获取当前登录人家庭成员求学情况 */
export function getCurrentFamilyStudy(
  data,
  desensitize: boolean,
  encrypt?: boolean,
) {
  return requestClient.post<
    List<PerBusinessFamilyStudyApi.BusinessFamilyStudy>
  >('/per/business-family-study/getCurrentFamilyStudy', data, {
    desensitize,
    encrypt,
  });
}
